import mutagen
import gio

#some media types enumerated

descriptions=[]
for i,(n,desc) in enumerate([
		("MT_UNKNOWN"			,"Failed"            ),
		("MT_REMOTE"			,"Copy"              ),
		("MT_AUDIO_CONVERTIBLE"	,"Convert"           ),
		("MT_AUDIO_UPLOADABLE"	,"Transfer"          ),
		("MT_VIDEO_CONVERTIBLE"	,"Convert"           ),
		("MT_VIDEO_UPLOADABLE"	,"Transfer"          ),
		]):
	globals()[n]=i
	descriptions.append(desc)
globals().pop("i")
globals().pop("n")
globals().pop("desc")

def get_description(n,pending):
	if n is MT_UNKNOWN:
		return descriptions[n]
	ret=descriptions[n]
	if pending:
		ret=ret+" Pending"
	return ret

def find_type(uri):
		try:
			file=gio.File(uri)
			if file.query_info(gio.FILE_ATTRIBUTE_STANDARD_TYPE).get_file_type()!=\
				gio.FILE_TYPE_REGULAR:
					return MT_UNKNOWN
			if not file.is_native():
				return MT_REMOTE
			audio=mutagen.File(file.get_path())
			if "".join(audio.mime).find("mp3") >= 0:
				return MT_AUDIO_UPLOADABLE
			else:
				return MT_AUDIO_CONVERTIBLE
		except:
			pass
		return MT_UNKNOWN



